'use strict'
let edge = ''


const path = require('path')
const UtilDLLPath = path.resolve(process.execPath || '', '..\\dll\\UtilDLL.dll')

const UtilDLLMethods = [
  'GetDllPath', // 获取dll的路径
  'GetSysFonts', // 获取系统安装字体
  'Word2Image', // word转图片
  'Pdf2Image', // pdf转图片
  'HtmlToWord', // html转word
  'Test',
  'SqliteExecuteNonQuery', // sqlite除了查询的执行方法
  'SqliteExecuteNonQueryByVariable',
  'SqliteExecuteNonQueryByVariableBatch',
  'SqliteQuery', // sqlite的查询方法
  'SqliteQueryByVariable',
  'SqliteChangePassword'
]
export const UtilDLL = {}

async function func (type, params) {
  try {
    return await new Promise((resolve, reject) => {
      let opt = {
        assemblyFile: UtilDLLPath,
        // typeName: 'UtilDLL.Class1',//DLL文件名.类名
        methodName: /* GetSysFonts */type // This must be Func<object,Task<object>>
      }
      edge.func(opt)(params, (error, result) => {
        if (error) return reject(error)
        if (Object.isObject(result) && result.error) reject(result)
        resolve(result)
      })
    })
  } catch (e) {
    console.log(e)
    return [{}]
  }
}

for (let type of UtilDLLMethods) {
  UtilDLL[type] = (params) => func(type, params)
}
